import axios from "axios";


function urlencode(data){
  let str = ''

  Object.keys(data).forEach(k=>{
    str += `${k}=${data[k]}&`
  })

  return str.slice(0, str.length-1)
}


function ajax(url, data={}, method='GET'){
  switch(method.toUpperCase()){
    case 'GET':
      return axios.get(`${url}?${urlencode(data)}`)

    case 'POST':
      return axios.post(url, data)
  }

}


export default ajax


